package thirdfactory.Impl;


import thirdfactory.Person;

import java.io.IOException;
import java.util.*;

public class MarkPersonFactory {
    //放在静态代码块中，new出来的时候直接读取配置文件，然后实例化全部对象

    //定义一个map集合，用来封装
    static Map map;
    static {
        Properties properties = new Properties();
        map = new HashMap<>();
        try {
            properties.load(MarkPersonFactory.class.getClassLoader().getResourceAsStream("person01.properties"));
            //获取配置文件中所有的key和value
            Enumeration<?> enumeration = properties.propertyNames();
            while (enumeration.hasMoreElements()) {
                //获取key元素
                String key = enumeration.nextElement().toString();
                String property = properties.getProperty(key);
                Object o = Class.forName(property).newInstance();
                map.put(key,o);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //封装！隐藏具体细节，开放一个共有的方法
    public Object getMarkPersonFactory(String beanName){
        return map.get(beanName);
    }
}
